package com.bailong.administrator.ausedcar.ui.biblefragment;


import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bailong.administrator.ausedcar.R;
import com.bailong.administrator.ausedcar.ui.biblebuycarfragment.BibleBuyCarFragment;
import com.bailong.administrator.ausedcar.ui.bibleloanfragment.BibleLoanFragment;
import com.bailong.administrator.ausedcar.ui.biblesellcarfragment.BibleSellCarFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
//宝典碎片
public class BibleFragment extends Fragment {

    @Bind(R.id.bible_tablayout)
    TabLayout bibleTablayout;
    @Bind(R.id.bible_viewpager)
    ViewPager bibleViewpager;
    private View view;
    private Context mcontext;
    private Activity activity;
    private String[] title;
    private List<Fragment> fragmentList = new ArrayList<>();

    private BibleBuyCarFragment bibleBuyCarFragment;
    private BibleLoanFragment bibleLoanFragment;
    private BibleSellCarFragment bibleSellCarFragment;
    private BiblePagerAdapter pagerAdapter;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activity = getActivity();

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_bible,container, false);
        ButterKnife.bind(this, view);
        initData();
        fragemntSetAdapter();
        return view;
    }

    private void initData() {
        bibleBuyCarFragment = new BibleBuyCarFragment();
        bibleSellCarFragment = new BibleSellCarFragment();
        bibleLoanFragment = new BibleLoanFragment();
        title = getResources().getStringArray(R.array.bible_tablayout);
        fragmentList.add(bibleBuyCarFragment);
        fragmentList.add(bibleSellCarFragment);
        fragmentList.add(bibleLoanFragment);

    }

    private void fragemntSetAdapter() {
        pagerAdapter = new BiblePagerAdapter(getActivity().getSupportFragmentManager(), fragmentList, title);
        bibleViewpager.setAdapter(pagerAdapter);
        bibleTablayout.setupWithViewPager(bibleViewpager);


    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
